package com.ruicar.afs.cloud.apply.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruicar.afs.cloud.common.core.entity.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @description: 客户地址明细表
 * @author: sijun.yu
 * @date: 2020/5/11 18:11
 */
@Data
@TableName(value = "apply_cust_address_details", autoResultMap = true)
@Accessors(chain = true)
public class ApplyCustAddressDetails extends BaseEntity<ApplyCustAddressDetails> {

    /**
     * 申请编号
     */
    private String applyNo;
    /**
     * 客户号
     */
    private Long custId;
    /**
     * 地址类型;户籍地址、居住地址、单位地址
     */
    private String addressType;
    /**
     * 房产类型
     */
    private String houseType;
    /**
     * 房产面积
     */
    private String houseArea;
    /**
     * 房产起始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date houseStartDate;
    /**
     * 省份
     */
    private String province;
    /**
     * 城市
     */
    private String city;
    /**
     * 区/县
     */
    private String county;
    /**
     * 街道
     */
    private String street;
    /**
     * 行政区划代码;国标码
     */
    private String gbCode;
    /**
     * 详细地址
     */
    private String detailAddress;
    /**
     * 邮政编码
     */
    private String postalCode;
    /**
     * 是否默认通讯地址;是、否
     */
    private Boolean isDefault;
    /**
     * 有效状态;有效、无效
     */
    private String validStatus;
    /**
     * 是否户籍地址
     */
    private String isMain;
    /**
     * 组合显示
     */
    @TableField(exist = false)
    private String[] detailAddressTemp;

    public String[] getDetailAddressTemp() {
        if (StringUtils.isEmpty(this.province)
                && StringUtils.isEmpty(this.city)
                && StringUtils.isEmpty(this.county)
                && StringUtils.isEmpty(this.street)) {
            return null;
        } else {
            return new String[]{this.province, this.city, this.county, this.street};
        }
    }

    public void setDetailAddressTemp(String[] detailAddressTemp) {
        if (detailAddressTemp != null) {
            if (detailAddressTemp.length >= 1) {
                this.province = detailAddressTemp[0];
            }
            if (detailAddressTemp.length >= 2) {
                this.city = detailAddressTemp[1];
            }
            if (detailAddressTemp.length >= 3) {
                this.county = detailAddressTemp[2];
            }
            if (detailAddressTemp.length >= 4) {
                this.street = detailAddressTemp[3];
            }
            this.detailAddressTemp = detailAddressTemp;
        }
    }

}
